package org.imraniqbal.pacman;

import java.awt.Color;
import java.awt.Graphics2D;
//import java.net.URL;
import java.util.Vector;

import org.imraniqbal.engine.Game;
import org.imraniqbal.engine.GameController;
import org.imraniqbal.engine.GamePanel;
import org.imraniqbal.engine.Mappable;

public class PacmanPanel extends GamePanel<PacmanGame> {

	private static final long serialVersionUID = 322562410916546825L;
	/**
	 * Creates a game panel with a blue maze walls
	 * @param g Current Instance of game
	 * @author imran
	 */
	public PacmanPanel(Game g) {
		super(g);
		this.setMazeColor(new Color(0,255,0));
	}
	/**
	 * Handles the drawing of specific mappables
	 * @author imran
	 */
	@Override
	protected void DrawMappable(Vector<Mappable> mappable, Graphics2D g2d) {
		try{
			for( Mappable m : mappable){
				int y = m.getY();
				int x = m.getX();
				if( m instanceof Pacman){
					DrawImage(g2d, x*GamePanel.defaultTileSize, y*GamePanel.defaultTileSize, creatImage("gfx/pacman/pacmanimg.png"));
					//DrawImage(g2d, x*GamePanel.defaultTileSize, y*GamePanel.defaultTileSize, creatImage(this.getClass().getResource("/gfx/pacmanimg.png")));
				}
				else if( m instanceof Ghost){
					DrawImage(g2d, x*GamePanel.defaultTileSize, y*GamePanel.defaultTileSize, creatImage("gfx/pacman/ghostimg" + ((Ghost)m).getID() + ".png"));
					//DrawImage(g2d, x*GamePanel.defaultTileSize, y*GamePanel.defaultTileSize, creatImage(this.getClass().getResource("/gfx/ghostimg" + ((Ghost)m).getID() + ".png")));
				}
				else if( m instanceof BigPill){
					DrawImage(g2d, x*GamePanel.defaultTileSize, y*GamePanel.defaultTileSize, creatImage("gfx/pacman/bigpill.png"));
					//DrawImage(g2d, x*GamePanel.defaultTileSize, y*GamePanel.defaultTileSize, creatImage(this.getClass().getResource("/gfx/bigpill.png")));
				}
				else{
					DrawImage(g2d, x*GamePanel.defaultTileSize, y*GamePanel.defaultTileSize, creatImage("gfx/pacman/smallpill.png"));
					//DrawImage(g2d, x*GamePanel.defaultTileSize, y*GamePanel.defaultTileSize, creatImage(this.getClass().getResource("/gfx/smallpill.png")));
				}
			}
		}catch(Exception e){
			System.out.println("Error while drawing image: " + e.getMessage());
		}
	}
	/**
	 * Starts a new Game
	 * @author imran
	 */
	@Override
	public void newGame() {
		PacmanGame mg = new PacmanGame();
		setGame(mg);
		removeGc(getGc());
		setGc(new GameController<PacmanGame>(mg, this));
		
		repaint();
	}

}
